package com.huahua.bigdata.spark.rdd.operate;

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;

import java.util.Arrays;
import java.util.List;

public class Spark15_Operate_Action {
    public static void main(String[] args) {
        SparkConf conf = new SparkConf();
        conf.setMaster("local");
        conf.setAppName("spark");
        JavaSparkContext jsc = new JavaSparkContext(conf);
        List<Integer> list = Arrays.asList(1, 2, 3, 4);
        JavaRDD<Integer> rdd = jsc.parallelize(list, 2);
        JavaRDD<Integer> mapRDD = rdd.map(num -> {
            System.out.println("num = " +num);
            return num * 2;
        });
        // TODO 行动算子
        //      转换算子的目的: 将旧的RDD转换成新的RDD, 为了组合多个RDD的功能
        //
        mapRDD.collect().forEach(System.out::println);

        jsc.close();
    }

}
